package com.cj.mobile.iabp.app.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


public class HandleResponseCode {
    public static void onHandle(Context context, int status, boolean isCenter) {
        Toast toast = new Toast(context);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(CommonUtils.getLayout(context, "jmui_default_toast"), null);
        TextView content = (TextView) view.findViewById(CommonUtils.getViewID(context, "jmui_toast_content_tv"));
        switch (status) {
            case 0:
                break;
            case 1000:
                content.setText(CommonUtils.getString(context, "jmui_record_voice_permission_denied"));
                break;
            case 1001:
                content.setText(CommonUtils.getString(context, "jmui_local_picture_not_found_toast"));
                break;
            case 1002:
                content.setText(CommonUtils.getString(context, "jmui_user_already_exist_toast"));
                break;
            case 1003:
                content.setText(CommonUtils.getString(context, "jmui_illegal_state_toast"));
                break;
            default:
                content.setText("Response code: " + status);
                break;
        }
        if (isCenter) {
            toast.setGravity(Gravity.CENTER, 0, 0);
        }
        view.getBackground().setAlpha(150);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
    }
}
